<?php
include('includes/commons.php');

if( !isSet($_POST['content']) ){
	die('Error');
}

if( !isSet($_POST['url']) ){
	$_POST['url'] = get_unique_url();
}

$note['url'] = xnote_escape($_POST['url']);
$note['content'] = xnote_escape(htmlspecialchars($_POST['content']));
$note['id'] = xnote_escape($_POST['id']);

$success = false;

if( user_can_edit($note['url']) ){
	$note = save_note($note);
	$success = !empty ($note );
}

header('Content-type: application/json');

if( $success ){
	echo '{"success":"true","note":{"url":"'.$note['url'].'","id":"'.$note['id'].'"}}';
}else{
	echo '{"success":"false"}';
}